#coding=utf-8
from django.contrib.auth.models import User, Group, Permission
from DjangoBbs.SiteSetting.models import SiteFileType
from PublicTool.BaseModel import Base_TimeModel

__author__ = 'czq'
from django.db import models


def get_Version_FilePath(instance, filename):
    #'static/upload/Users/headsculpture'
    return "headsculpture/%s/%s"%(instance.username,filename)

class UserInfo(models.Model):
    sex_man = 1
    sex_woman = 0
    sex_CHOICES = (
        (sex_man, '男'),
        (sex_woman, '女'),
    )
    user = models.OneToOneField(User)
    profession=models.CharField(u"职业",max_length=20,blank=True,null=True)
    description=models.TextField(u"个人说明",blank=True,null=True)
    QQ=models.CharField(u'QQ',max_length=15,blank=True,null=True)

    hometown=models.CharField(u"故乡",max_length=30,blank=True,null=True)
    location=models.CharField(u"所在地",max_length=30,blank=True,null=True)
    sex=models.BooleanField(u"性别",choices=sex_CHOICES,default=sex_man)
    birthday=models.DateField(u"生日",blank=True,null=True)
    phone=models.CharField(u"手机",max_length=15,blank=True,null=True)
    def __unicode__(self):
        return self.user.first_name
    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = '用户信息'
class UserSetting(models.Model):
    user = models.OneToOneField(User)
    pageSize_Theme=models.PositiveSmallIntegerField(u'每页主题数',default=10,help_text=u'版块每页显示的主题数')
    pageSize_Reply=models.PositiveSmallIntegerField(u'每页回复数',default=5,help_text=u'看主题时每页回复数')
    def __unicode__(self):
        return self.user.username
    class Meta:
        verbose_name = '用户设置'
        verbose_name_plural = '用户设置'

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    nickName=models.CharField(verbose_name=u"昵称",max_length=10,blank=True,null=True)
    signature=models.CharField(u'个性签名',max_length=50,blank=True,null=True)
    extcredits1=models.IntegerField(u'积分1',default=0)
    extcredits2=models.IntegerField(u'积分2',default=0)
    extcredits3=models.IntegerField(u'积分3',default=0)
    themeCount=models.IntegerField(u'主题数量',default=0)
    replyCount=models.IntegerField(u'回复数量',default=0)
    integral=models.IntegerField(u'积分',default=0)
    headsculpture=models.ImageField(u"头像",upload_to=get_Version_FilePath,blank=True,null=True)
    group=models.ForeignKey(Group,verbose_name=u'组')#,default=Group.objects.get(id=1)


    def __unicode__(self):
        return self.user.username
    class Meta:
        verbose_name = '用户'
        verbose_name_plural = '用户'






class GroupProfile(Base_TimeModel):
    group=models.OneToOneField(Group,verbose_name=u'名称')
    #name=models.CharField(u'名称',max_length=10)
    themeBusinessExtcreditMax=models.PositiveSmallIntegerField(u'主题(附件)最高售价',default=0,help_text=u'主题(附件)出售使得作者可以将自己发表的主题(附件)隐藏起来,只有当浏览者向作者支付相应的交易积分后才能查看主题(附件)内容.此处设置用户出售主题(附件)时允许设置的最高价格,0 为不允许用户出售.')
    fileSingleMaxSize=models.SmallIntegerField(u'论坛上传单个附件允许的最大尺寸',default=0,help_text=u'单位:k')
    ileDayMaxSize=models.SmallIntegerField(u'论坛每天允许上传附件大小',default=0,help_text=u'单位:k')
    fileType=models.ManyToManyField(SiteFileType,verbose_name=u'允许附件类型',null=True,blank=True)
    color=models.CharField(u'颜色',max_length=10,null=True,blank=True)
    readPerm=models.PositiveSmallIntegerField(u'阅读权限',default=1)
    Star=models.PositiveSmallIntegerField(u'星星数',default=0)
    msgCount=models.PositiveSmallIntegerField(u'短消息最多条数',default=20)

    TYPE_EXTCREDITS=0
    TYPE_SYSTEM=1
    TYPE_SELECT=(
        (TYPE_EXTCREDITS,u'积分用户组'),
        (TYPE_SYSTEM,u'系统用户组'),
    )
    type=models.PositiveSmallIntegerField(u'组别',choices=TYPE_SELECT,default=TYPE_EXTCREDITS)
    extcreditsMin=models.IntegerField(u'积分下限',help_text=u'所属该用户组用户的最低积分数',default=0)
    extcreditsMax=models.IntegerField(u'积分上限',help_text=u'所属该用户组用户的最高积分数',default=0)
    perm=models.ManyToManyField(Permission,null=True,blank=True,verbose_name=u'权限',help_text=u'可以操作的内容<br/>')

    remark=models.CharField(u'说明',max_length=200,null=True,blank=True)
    imgUrl=models.URLField(u'图标链接',max_length=50,null=True,blank =True)

    def __unicode__(self):
        return self.group.name
    class Meta:
        verbose_name = '用户组'
        verbose_name_plural = '用户组'
